﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DAL;
using CommontLibrary;
public partial class Admin_UserControl_HocVien_insertLevelA : System.Web.UI.UserControl
{
#region "Member variables"
    private int intUserList = 0;
    private int intDiem = 3;
    private int intUserID = 0;
    private int intHocVienID = 0;
    private int intModuleID = 0;
    bool boolRead = false;
    bool boolWrite = false;
    bool boolUpdate = false;
    bool boolDelete = false;
    DAHocVien objHocVien;
    DANguoidung objNguoidung;
    DANguon objNguon;
    DAHocVienLV6LV8 objLV6LV8;
    DALog objLog;
    int intLevelID = 1;
#endregion
#region "Parametter variables"
    // Ham lay Bind du lieu
    public SqlConnection ConnectionView
    {
        get
        {
            object obj2 = this.ViewState["ConnectionView"];
            if (obj2 != null)
            {
                return (SqlConnection)obj2;
            }
            return null;
        }
        set
        {
            this.ViewState["ConnectionView"] = value;
        }
    }
    #endregion
#region "Private methods"
   
   
    private void loadTitle(string strTen, string strMaHocVien)
    {
        try
        {
            System.Web.UI.HtmlControls.HtmlControl t = (System.Web.UI.HtmlControls.HtmlControl)this.Page.FindControl("lblTitle");
            t.Controls.Clear();
            t.Controls.Add(new LiteralControl(strMaHocVien + " - " + strTen));
        }
        catch { }
    }
    // Hien thi NguoiTimNguon tren datagrid
    private void loadHocVienID(int intHocVienID)
    {
        DataRow drHocVien = objHocVien.loadHocVienID(intHocVienID);
        if (drHocVien != null)
        {
            
        }
    }
    //LV6-LV8
    private void loadL6L8ID(int LevelID, bool boolCheck)
    {
        try
        {
            DataRow drLV6LV8 = objLV6LV8.loadHocVienLV6LV8ID(intHocVienID, LevelID);
            BindData.bindTextBox(this.txtdenthiLV6LV8, "", drLV6LV8["DenThi"].ToString());
            BindData.bindTextBox(this.txtBaithiLV6LV8, "", drLV6LV8["BaiThi"].ToString());
            BindData.bindTextBox(this.txtcodiemLV6LV8, "", drLV6LV8["CoDiem"].ToString());
            BindData.bindTextBox(this.txtgiaybaotrungtuyenLV6LV8, "", drLV6LV8["GiayBaoTrungTuyen"].ToString());
            BindData.bindTextBox(this.txtnhandcgiaybaotrungtuyenLV6LV8, "", drLV6LV8["NhanDuocGiayBaoTrungTuyen"].ToString());
            BindData.bindTextBox(this.txtnophocphiLV6LV8, "", drLV6LV8["NopHocPhi"].ToString());
            BindData.bindTextBox(this.txtNopHoSoLV6LV8, "", drLV6LV8["NopHoSo"].ToString()); ;
            BindData.bindTextBox(this.txtGhichuLV6LV8, "", drLV6LV8["GhiChu"].ToString()); ;
            DateTime dateStartDate = Convert.ToDateTime(drLV6LV8["NgayGoi"].ToString().Trim());
            this.txtNgayGoiGanNhatV6LV8.SelectedDate = dateStartDate;
            BindData.bindTextBox(this.txtNoiDungNgayGoiGanNhatV6LV8, "", drLV6LV8["NoiDungNgayGoi"].ToString());
            BindData.bindTextBox(this.txtDuKienNhapHoc, "", drLV6LV8["DuKienNhapHoc"].ToString());
            BindData.bindTextBox(this.txtThucNhapHoc, "", drLV6LV8["ThucNhapHoc"].ToString());
            
        }
        catch { }
    }
    private void CreateL6L8(int LevelID, bool checkUpdate, int intTrangthai)
    {
        string strDuKienNhapHoc = this.txtDuKienNhapHoc.Text.Trim();
        string strThucNhapHoc = this.txtThucNhapHoc.Text.Trim();
        int intChẹck = objLV6LV8.updateHocVienLV6LV8(intHocVienID, strDuKienNhapHoc, strThucNhapHoc);
        if (intChẹck > 0)
        {
            if (checkUpdate)
            {
                this.lblMess.Text = "Sửa bản ghi thành công";
                lblScript.Text = "<script language=javascript >ResetFormParent('fromDefault');</script>";
            }
        }
        else if (intChẹck == 0)
        {
            this.lblMess.Text = "Bản ghi này đã có trong dữ liệu!";
        }
        else
        {
            this.lblMess.Text = "Lỗi trong quá trình sửa bản ghi!";
        }
    }
    private void ResetLV6LV8()
    {
        loadL6L8ID(intLevelID, false);
    }
    //End LV6-LV8    
#endregion
#region "Events handle"
    //Check quyen han su dung
    private void CheckUserModule(int UserID, int ModuleID)
    {
       
    }
    private void loadDataAccess()
    {
        SqlConnection sqlConnec = ConnectData.getConnection();
        objHocVien = new DAHocVien(sqlConnec);
        objNguoidung = new DANguoidung(sqlConnec);
        objNguon = new DANguon(sqlConnec);
        objLV6LV8 = new DAHocVienLV6LV8(sqlConnec);
        objLog = new DALog(sqlConnec);
    }
    //Main load
    protected void Page_Load(object sender, EventArgs e)
    {
        intUserID = Convert.ToInt32(Session["UserID"].ToString().Trim());
        loadDataAccess();

        if (Request.QueryString["HocVienID"] != null)
        {
            bool boolCheck = StringUntil.checkNumber(Request.QueryString["HocVienID"].Trim());
            if (boolCheck)
            {
                intHocVienID = Convert.ToInt32(Request.QueryString["HocVienID"].Trim());
            }
        }
        if (Request.QueryString["LevelView"] != null)
        {
            bool boolCheck = StringUntil.checkNumber(Request.QueryString["LevelView"].Trim());
            if (boolCheck)
            {
                intLevelID = Convert.ToInt32(Request.QueryString["LevelView"].Trim());
            }
        }
        if (Request.QueryString["UserList"] != null)
        {
            bool boolCheck = StringUntil.checkNumber(Request.QueryString["UserList"].Trim());
            if (boolCheck)
            {
                intUserList = Convert.ToInt32(Request.QueryString["UserList"].Trim());
            }
        }
        if (!Page.IsPostBack)
        {                        
            CheckUserModule(intUserID, intModuleID);
            loadHocVienID(intHocVienID);
            loadL6L8ID(intLevelID, false);
        }
        this.hplCloseWindows.Attributes.Add("OnClick", "javascript:CloseWin();");
        //this.btnUpdate.Attributes.Add("OnClick", "javascript:ResetForm();");        
    }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            CreateL6L8(intLevelID, true, 0);
            objLog.insertLog(intLevelID, intHocVienID, 4, intUserID);
        }
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        ResetLV6LV8();
    }
#endregion
}
